package com.bj58.migrate.update;

import java.util.List;

import org.apache.log4j.Logger;

import com.bj58.migrate.ScfProxy;
import com.bj58.sfft.imc.entity.Info;
import com.bj58.spat.scf.server.contract.entity.Out;

public abstract class AbsDataHandler implements DataHandler{

	private Logger logger = Logger.getLogger( AbsDataHandler.class );

	public void handle( String condition, String[] args ){

		int page = 1;

		logger.info( "Handling.... " + args[ 2 ] + " " + condition );
		
		while( true ){

			Out< Integer > total = new Out< Integer >();
			total.setOutPara( new Integer( 0 ) );

			List< Info > infolist = null;

			try{
				infolist = ScfProxy.imc_InfoProviderWithIndex().GetInfo( condition, "*", 50, page++, "SortID", "desc", total );
			}
			catch( Exception e ){
				logger.error( "AbsDataUpdateHandler get infos Exception:" + condition ,e);
				e.printStackTrace();
			}

			if( infolist == null || infolist.size() == 0 ){
				break;
			}
			logger.info( "Handle " + args[ 2 ] + " page " + ( page - 1 ) + " " + condition + "......size:" + infolist.size() );
			for( Info info : infolist ){
				if( info != null ){
					try {
                        deal( info, args );
					} catch (Exception e) {
						logger.error("Update info-----id:"+info.getInfoID() +"-----userid:"+info.getUserID()+"--- Error",e);
					}
					
				}
			}
		}
	}

	protected abstract void deal( Info info, String[] args );
}
